home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / IAC_STUF / TESTAPP.C < prev   
C/C++ Source or Header  |  1989-11-29  |  2KB  |  82 lines

  1. #include "IAC.p"
  2.  
  3. #include <console.h>
  4.  
  5. struct IACBuffer {
  6.     int charAvail;
  7.     int bufSize;
  8.     char buffer[];
  9.     };
  10.  
  11. main()
  12. {
  13.     char command[100];
  14.     int n;
  15.     char buf[1000];
  16.     int myNum, otherNum;
  17.     EventRecord event;
  18.     struct IACBuffer *otherBuf, *myBuf;
  19.     char c, *cmd;
  20.     
  21.     printf("Running IAC Test Application A...\n\n");
  22.     
  23.     printf("Enter application numbers (thisApp, otherApp): ");
  24.     scanf("%d,%d", &myNum, &otherNum);
  25.     printf("\n\n");
  26.     
  27.     csetmode(C_RAW, stdin);
  28.  
  29.     fflush(stdin);
  30.         
  31.     if (IACInit() != noErr) {
  32.         printf("Error opening driver.\n");
  33.         exit(-1);
  34.         }
  35.  
  36.     printf("Registering myself.\n\n");
  37.     myBuf = IACRegister(myNum, 1024);
  38.     
  39.     IACClear(myBuf);
  40.     
  41.     do {
  42.         printf("Trying to find the other application (press 'q' to quit).\n");
  43.  
  44.         if (WaitNextEvent(keyDownMask, &event, 60L, NULL))
  45.             if ((event.message & charCodeMask) == 'q')
  46.                 exit(0);
  47.                         
  48.         otherBuf = IACLookup(otherNum);
  49.         
  50.         } while (otherBuf == 0L);
  51.  
  52.     /* Watch for any input and send it to the other application.  Also watch for
  53.        messages from the other application and display them. */
  54.     *command = '\0';
  55.     *buf = '\0';
  56.     printf("Waiting for user/IAC input...\n\n");
  57.     do {
  58.         /* Is there any user input waiting? */
  59.         if ((c = getchar()) != EOF) {
  60.             cmd = command;
  61.             *cmd++ = c;
  62.             putchar(c);
  63.             while ((c = getchar()) != '\r')
  64.                 if (c != EOF) {
  65.                     *cmd++ = c;
  66.                     putchar(c);
  67.                     }
  68.             *cmd = '\0';
  69.             IACSend(otherBuf, command, strlen(command) + 1);
  70.             printf("\n");
  71.             }
  72.     
  73.         /* Is there a message from the other application waiting? */
  74.         n = IACGet(myBuf, buf, sizeof(buf));
  75.         if (n > 0)
  76.             printf("Received '%s' from other application.\n", buf);
  77.     
  78.       } while(strcmp(command,"quit") && strcmp(buf, "quit"));
  79.  
  80.      IACDeRegister(myNum);
  81. }
  82.